package cn.wolfcode.crm.query;

import lombok.Getter;
import lombok.ToString;

import java.util.Collections;
import java.util.List;

@Getter
@ToString
public class PageResult {
    private Integer currentPage;
    private Integer pageSize;
    private Integer rows;
    private List<?> result;
    private Integer prevPage;
    private Integer nextPage;
    private Integer totalPage;

    public PageResult(Integer pageSize){
        this(1,pageSize,0, Collections.EMPTY_LIST);
    }

    //我们利用构造方法将计算的得到的参数写上去,方便我们用的时候取
    public PageResult(Integer currentPage, Integer pageSize, Integer rows, List<?> result) {
        super();
        //这四个我们需要获取的
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.rows = rows;
        this.result = result;

        //这三个通过上面算出来的
        this.totalPage = rows % pageSize == 0 ? rows / pageSize : rows / pageSize + 1;
        this.prevPage = currentPage > 1 ? currentPage - 1 : 1;
        this.nextPage = currentPage < totalPage ? currentPage + 1 : totalPage;
    }
}